// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
let request = require('request');
module.exports = {
	_before: function () { // 通用预处理器

	},
	login(code) {
		return new Promise((resolve, reject) => {
			request({
				url: `https://api.weixin.qq.com/sns/jscode2session?appid=wx848300787475c5e6&secret=1ce3113e067e2b691e1f4efa7da257ef&grant_type=authorization_code&js_code=${code}`,
				method: 'get',
				json: true,
				heades: {
					"content-type": "application/json"
				}
			}, (error, response, body) => {
				console.log(error, response, body, "----start----");
				if (!error && response.statusCode == 200) {
				    console.log(body.openid + "----openid----");
				    console.log(body.session_key + "----session_key----");
					resolve(body.openid);
				  } else {
					 reject(error); 
				  }
			})
		})
	},
	loginZYapp(code) {
		return new Promise((resolve, reject) => {
			request({
				url: `https://api.weixin.qq.com/sns/jscode2session?appid=wx996434cef19936b2&secret=70d69a19c7fcc8912bbe6182a948f813&grant_type=authorization_code&js_code=${code}`,
				method: 'get',
				json: true,
				heades: {
					"content-type": "application/json"
				}
			}, (error, response, body) => {
				console.log(error, response, body, "----start----");
				if (!error && response.statusCode == 200) {
				    console.log(body.openid + "----openid----");
				    console.log(body.session_key + "----session_key----");
					resolve(body.openid);
				  } else {
					 reject(error); 
				  }
			})
		})
	}
}
